<?php
// 图片操作
 import('Com.Images.ImgSplice');
 
class ImageAction extends Action {
    var $PickRoot= "";
   
    function __construct(){
        $this->PickRoot=PICK_DIR.MODULE_NAME.DIRECTORY_SEPARATOR;
        if(!is_dir($this->PickRoot)){
            mkdir($this->PickRoot);
        }

    }
    

    
    public function index(){
		// $this->StatisticsImgaes($this->SoDir($this->PickRoot));
       
        // $imgsplice = new ImgSplice($this->PickRoot);
        // $imgsplice->temps();
    }
    /***
     * 	logCmd($this->get_redirect_url("http://www.52deli.com/link/1594481"));
     *  logCmd($this->get_redirect_url("http://www.coo8.com/product/124359.html"));	
     *	获取URL地址
     */
    
    public function get_redirect_url($url){
    	$redirect_url = null;
    
    	$url_parts = @parse_url($url);
    	if (!$url_parts) return false;
    	if (!isset($url_parts['host'])) return false; //can't process relative URLs
    	if (!isset($url_parts['path'])) $url_parts['path'] = '/';
    
    	$sock = fsockopen($url_parts['host'], (isset($url_parts['port']) ? (int)$url_parts['port'] : 80), $errno, $errstr, 30);
    	if (!$sock) return false;
    
    	$request = "HEAD " . $url_parts['path'] . (isset($url_parts['query']) ? '?'.$url_parts['query'] : '') . " HTTP/1.1\r\n";
    	$request .= 'Host: ' . $url_parts['host'] . "\r\n";
    	$request .= "Connection: Close\r\n\r\n";
    	fwrite($sock, $request);
    	$response = '';
    	while(!feof($sock)) $response .= fread($sock, 8192);
    	fclose($sock);
    
    	if (preg_match('/^Location: (.+?)$/m', $response, $matches)){
    		if ( substr($matches[1], 0, 1) == "/" )
    			return $url_parts['scheme'] . "://" . $url_parts['host'] . trim($matches[1]);
    		else
    			return trim($matches[1]);
    
    	} else {
    		return false;
    	}
    
    }
   
    
   
}